package com.example.servicegateway.route.rule.config;

import com.example.servicegateway.route.rule.validator.AddRuleValidator;
import com.example.servicegateway.route.rule.validator.impl.LocalAddRuleValidator;
//import com.example.servicegateway.route.rule.validator.impl.RedisAddRuleValidator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * 添加规则校验器配置
 * @author K
 */
@Configuration
public class AddRuleValidatorConfig {

    /**
     * 与存放在redis数据进行校验
     * @param stringRedisTemplate stringRedisTemplate
     * @return 返回校验器接口
     */
//    @Bean
//    @ConditionalOnClass(StringRedisTemplate.class)
//    public AddRuleValidator redisAddRuleValidator(StringRedisTemplate stringRedisTemplate) {
//        return new RedisAddRuleValidator(stringRedisTemplate);
//    }

    /**
     * 与存放在本地List数据进行校验
     * @return 返回校验器接口
     */
    @Bean
    @ConditionalOnMissingBean(AddRuleValidator.class)
    public AddRuleValidator localAddRuleValidator() {
        return new LocalAddRuleValidator();
    }
}
